<template>
<div class="body">
<!-- <div @click="changeBg">换一张</div> -->
  <div class="index_main">
      <div>
        <div class="search">
            <input v-model="title_contains" @input="searchFn" type="text">
            <button @click="queryFn">搜索</button>
        </div>
        <div class="querybox">

        <div class="query" v-for="item in list" :key="item.id" @click="detail(item.id)">{{item.title}}</div>
        </div>
        </div>
    </div>
</div>
</template>

<script>
import {getCategory} from '@/api/category'
import bgapi from '@/api/bg'
export default {
data(){
    return{
        title_contains:'',
        pageSet:{
            _limit:5,
            _start:0
        },
        list:[]
    }
},
methods:{
       searchFn(){
          setTimeout(async() => {
              if(!this.title_contains){
                  this.list = []
                return
              }
              const {data} =  await getCategory({
                  ...this.pageSet,
                  title_contains:this.title_contains
              })
              console.log(data);
              this.list = data
          }, 10);
    },
    detail(id){
        this.$router.push({path:'/detail',query:{id}})
    },
    queryFn(){
        this.$router.push({
            path:'/category',
            query:{
                title_contains:this.title_contains
            }
        })
    },
    async changeBg(){
     const res =   await bgapi({
         url:'/index.php',
         params:{
             c:'WallPaper',
             a:'getAppsByCategory' ,
             cid:6,
             from:'360chrome'  
         }
     })
     console.log(res);
    }
}
}
</script>

<style lang="less" scoped>
 .body {
            height: calc(~'100vh - 50px');
            background: url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ffile.moyublog.com%2Fd%2Ffile%2F2021-02-10%2F325f6f5039c198707d4f896b4e859a92.jpg&refer=http%3A%2F%2Ffile.moyublog.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648785614&t=d48cbbc6171515a885f60eb6d032927e);
            background-size: cover;
        }
  /* 首页内容 */
        .index_main {
          height: 80vh;
           display: flex;
           flex-direction: column;
           align-items: center;
           .querybox{
               width: 380px;
               height: auto;
               margin-top: 5px;
               
           }
           .query{
               margin-left:20px ;
               width: 380px;
               padding: 0 10px;
               line-height: 1.5;
               cursor: pointer;
               color: #bbb;
               background-color: #fff;
               &:hover{
                   color: #fff;
                   background-color: aqua;
               }
               &:last-child{
                   border-radius: 0 0 5px 5px;
               }
               &:first-child{
                   border-radius: 5px 5px 0 0;
               }
           }
        }

        .index_main .search {
            width: 500px;
            height: 45px;
            display: flex;
            margin-top: 160px;
            justify-content: center;
            background-color: #fff;
            border-radius: 25px;
            overflow: hidden;
           
        }
         .index_main .search button{
                width: 100px;
                height:45px;
                color: #fff;
                cursor: pointer;
                background-color: aqua;
                &:hover{
                    transition: all 0.3s;
                    border-radius: 25px;
                    color: pink;
                background-color: darkmagenta;

                }
            }
        .index_main .search input{
            width: 400px;
            height: 45px;
            padding: 0 20px;
            /* background-color: red; */
           
        }

</style>